package priv.wjh.study.cloud.feign.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import priv.wjh.study.cloud.feign.ArgsException;

import javax.servlet.http.HttpServletRequest;

/**
 * //TODO
 *
 * @author wangjunhao
 **/
@Slf4j
@RestControllerAdvice
public class MyExceptionControllerAdvice {

    @ExceptionHandler(ArgsException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public String badRequest(HttpServletRequest request, ArgsException e) {
        log.info("Exception: ", e);
        return "args exception";
    }


    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String notFountHandler(HttpServletRequest request, Exception e) {
        log.info("Exception: ", e);
        return e.getMessage();
    }

}
